package cn.selfiot.iotman.view.item;

import cn.selfiot.iotman.core.I18N;
import cn.selfiot.iotman.model.mqtt.messge.ActionItem;
import cn.selfiot.iotman.view.ResourceConstants;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.layout.VBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ResourceBundle;

/**
 * @author hugo
 * @since 2020/8/14
 */
public class ListItem extends VBox {
    private static final Logger LOGGER = LoggerFactory.getLogger(ListItem.class);
    
    private ActionItem actionItem;
    
    public ListItem(ActionItem actionItem) {
        super();
        this.actionItem = actionItem;
        String fxml = ResourceConstants.PUB_ITEM_RES;
        try {
            ResourceBundle bundle = I18N.getBundle();
            FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml), bundle);
            ListItemController controller = new ListItemController();
            controller.setActionItem(actionItem);
            loader.setController(controller);
            
            Node node = loader.load();
            this.getChildren().add(node);
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        }
    }
    
    public ActionItem getActionItem() {
        return actionItem;
    }
    
    public void setActionItem(ActionItem actionItem) {
        this.actionItem = actionItem;
    }
}
